<?php

global $_W, $_GPC;
$_GPC['menu'] = 'card';
$code = $_GPC['code'];

if (empty($code)) {
    $code = 'pro';
}
$item = M('setting')->getSetting($code);

if (empty($item)) {
    $item = array();
}
if ($_W['ispost']) {
    $data = array();
    $data['codename'] = $code;
    $_POST = array_merge($item, $_POST);
    //支付证书上传
    if (!empty($_FILES)) {
        foreach ($_FILES as $key => $file) {
            $name = $file['name'];
            if (!empty($name)) {
                $ext = substr($name, strrpos($name, '.') + 1);
                if ($ext != 'pem') {
                    message("文件格式有误", referer(), 'error');
                }
                $temp = $file['tmp_name'];
                $content = file_get_contents($temp);
                $path = IA_ROOT . '/addons/weidun_question/assets/cert/' . $_W['uniacid'] . '/';
                if (!is_dir($path)) {
                    load()->func('file');
                    mkdirs($path);
                }
                $cert_file = $path . $name;
                if (!is_file($cert_file)) {
                    file_put_contents($cert_file, $content);
                }
                $_POST[$key] = $cert_file;
            }
        }
    }
    $data['value'] = iserializer($_POST);
    M('setting')->update($data);
    message('保存成功', referer(), 'success');
}
include $this->template('setting_' . $code);